<template>
  <div id="particulars">
    <v-detail
      :detailData="inputData"
      :inputConfig="inputConfig"
      :rules="rules"
      ref="detail"
    ></v-detail>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import detail from "commons/Detail";

export default {
  name: "particulars",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  data() {
    //自定义验证规则
    const numValidate = (rule, value, callback) => {
      let reg = /^\+?[0-9]\d*$/; //大于零的正整数
      if (!reg.test(value)) {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.inputData[rule.field] = 0;
        callback(new Error());
      } else {
        callback();
      }
    };
    //自定义验证规则
    const numXSValidate = (rule, value, callback) => {
      if (value === "") {
        callback(new Error());
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te);
        if (!flag) {
          if (value < 0) {
            this.$message.error(this.$t("app.inputNumberPlease"));
            this.inputData[rule.field] = 0;
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t("app.inputNumberPlease"));
          this.inputData[rule.field] = 0;
          callback(new Error());
        }
      }
    };
    return {
      inputConfig: [
        [
          {
            type: "input",
            label: this.$t("config.loc"),
            props: "loc",
          },
          {
            type: "select",
            label: this.$t("config.locType"),
            props: "locationtype",
            options: this.getOptions("querycodeLkup/LOCTYPE"),
          },
          {
            type: "select",
            label: this.$t("config.locCategory"),
            props: "locationcategory",
            options: this.getOptions("querycodeLkup/LOCCATEGRY"),
          },
          {
            type: "select",
            label: this.$t("config.locHandler"),
            props: "locationhandling",
            options: this.getOptions("querycodeLkup/LOCHDLING"),
          },
          {
            type: "input",
            label: this.$t("config.checkDigit"),
            props: "check digit",
            disabled: true,
          },
          {
            type: "select",
            label: "ABC",
            props: "abc",
            options: this.getOptions("querycodeLkup/LOCABC"),
          },
          {
            type: "select",
            label: this.$t("config.section"),
            props: "section",
            options: this.getOptions("querycodeLkup/LOCSECTION"),
          },
        ],
        [
          {
            type: "select",
            label: this.$t("config.locFlag"),
            props: "locationflag",
            options: this.getOptions("querycodeLkup/LOCFLAG"),
          },
          {
            type: "input",
            label: this.$t("common.status"),
            props: "status",
            disabled: true,
          },
          {
            type: "select",
            label: this.$t("config.area"),
            props: "putawayzone",
            options: this.getOptions("queryPutawayzoneDropDown"),
          },
          {
            type: "input",
            label: this.$t("config.routeSequence"),
            props: "logicallocation",
          },
          {
            type: "input",
            label: this.$t("config.interOtherSequence"),
            props: "interleavingsequence",
          },
          {
            type: "select",
            label: this.$t("config.commingleSku"),
            props: "comminglesku",
            options: this.getOptions("querycodeLkup/YESNO"),
          },
          {
            type: "select",
            label: this.$t("config.commingleLot"),
            props: "comminglelot",
            options: this.getOptions("querycodeLkup/YESNO"),
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.height"),
            props: "height",
          },
          {
            type: "input",
            label: this.$t("config.length"),
            props: "length",
          },
          {
            type: "input",
            label: this.$t("config.width"),
            props: "width",
          },
          {
            type: "input",
            label: this.$t("security.tier"),
            props: "loclevel",
          },
          {
            type: "input",
            label: this.$t("config.rowNo"),
            props: "row_number",
          },
          {
            type: "input",
            label: this.$t("config.putShelvesNo"),
            props: "put_shelves_number",
          },
          {
            type: "input",
            label: this.$t("config.pickShelvesNo"),
            props: "pick_shelves_number",
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.xCoord"),
            props: "xcoord",
          },
          {
            type: "input",
            label: this.$t("config.yCoord"),
            props: "ycoord",
          },
          {
            type: "input",
            label: this.$t("config.zCoord"),
            props: "zcoord",
          },
          {
            type: "input",
            label: this.$t("config.position"),
            props: "orientation",
          },
          {
            type: "input",
            label: this.$t("config.columnNo"),
            props: "column_no",
          },
          {
            type: "input",
            label: this.$t("config.layerNo"),
            props: "layer_no",
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.capacity"),
            props: "cubiccapacity",
          },
          {
            type: "input",
            label: this.$t("config.weightCapacity"),
            props: "weightcapacity",
          },
          {
            type: "input",
            label: this.$t("config.stackLimit"),
            props: "stacklimit",
          },
          {
            type: "input",
            label: this.$t("config.footprint"),
            props: "footprint",
          },
          {
            type: "checkbox",
            label: this.$t("config.autoship"),
            props: "autoship",
          },
          {
            type: "checkbox",
            label: this.$t("config.loseId"),
            props: "loseid",
          },
        ],
      ],
      rules: {
        height: [{ required: true, validator: numXSValidate, trigger: "blur" }],
        length: [{ required: true, validator: numXSValidate, trigger: "blur" }],
        width: [{ required: true, validator: numXSValidate, trigger: "blur" }],
        xcoord: [{ required: true, validator: numValidate, trigger: "blur" }],
        ycoord: [{ required: true, validator: numValidate, trigger: "blur" }],
        zcoord: [{ required: true, validator: numValidate, trigger: "blur" }],
        loclevel: [{ required: true, validator: numValidate, trigger: "blur" }],
        cubiccapacity: [
          { required: true, validator: numXSValidate, trigger: "blur" },
        ],
        weightcapacity: [
          { required: true, validator: numXSValidate, trigger: "blur" },
        ],
        stacklimit: [
          { required: true, validator: numXSValidate, trigger: "blur" },
        ],
        interleavingsequence: [
          { required: true, validator: numValidate, trigger: "blur" },
        ],
        row_number: [
          { required: true, message: this.$inputPlease('config.shelfRowNo'), trigger: "blur" },
        ],
        footprint: [
          { required: true, validator: numValidate, trigger: "blur" },
        ],
        loc: [{ required: true, validator: this.loc, trigger: "blur" }],
        locationtype: [
          {
            required: true,
            message: this.$selectPlease("config.locType"),
            trigger: "blur",
          },
        ],
        locationcategory: [
          {
            required: true,
            message: this.$selectPlease("config.locCategory"),
            trigger: "blur",
          },
        ],
        locationhandling: [
          {
            required: true,
            message: this.$selectPlease("config.locHandler"),
            trigger: "blur",
          },
        ],
        abc: [
          {
            required: true,
            message: this.$selectPlease("config.turnoverType"),
            trigger: "blur",
          },
        ],
        section: [
          {
            required: true,
            message: this.$selectPlease("config.section"),
            trigger: "blur",
          },
        ],
        locationflag: [
          {
            required: true,
            message: this.$selectPlease("config.locFlag"),
            trigger: "blur",
          },
        ],
        putawayzone: [
          {
            required: true,
            message: this.$selectPlease("config.putZone"),
            trigger: "blur",
          },
        ],
        comminglesku: [
          {
            required: true,
            message: this.$selectPlease("config.commingleSku"),
            trigger: "blur",
          },
        ],
        comminglelot: [
          {
            required: true,
            message: this.$selectPlease("config.commingleLot"),
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    loc(rule, value, callback) {
      if (value === "") {
        callback(new Error());
        this.inputData.logicallocation = "";
      } else {
        let reg = /^[a-z_A-Z0-9-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'<>~\·`\?:;|]+$/; //匹配字母、数字及所有英文符号的正则表达式
        if (!reg.test(value)) {
          this.$message.error(this.$t("app.dataIsNotZh"));
          this.inputData.loc = "";
          this.inputData.logicallocation = "";
          callback(new Error());
        } else {
          if (this.inputData.logicallocation == "") {
            this.inputData.logicallocation = value;
          }
          callback();
        }
      }
    },
  },
  mounted() {},
  watch: {
    /*'inputData.loc': {
            handler(data) {
                if (this.inputData.logicallocation == "") {
                    this.inputData.logicallocation = data;
                }
            },
        }*/
  },

  components: {
    "v-detail": detail,
  },
};
</script>

<style scoped></style>
